package com.projectName.www.dao;

import com.projectName.www.service.OpenBusiness;
import com.projectName.www.po.orders;

import java.sql.ResultSet;

public class S_J_orders_dao {
    //填充表格
    //i=0：未处理的订单
    public static ResultSet filltable(int i) throws Exception {
        String sql = "select * from orders where bool_shop =1";
        ResultSet r1 = BaseDao.executeQuery(sql);
        String Sql = "select * from orders where bool_shop =2 or bool_shop=3";
        ResultSet r2 = BaseDao.executeQuery(Sql);
        if (i == 0) return r1;
        else return r2;
    }

    //接单&&退回
    //i=2：表示接单 3：表示退回
    public static boolean yesORno(orders r,int k) throws Exception {
        String sql = "update orders set bool_shop = ? where Buyers = ? and business = ? and dishename = ? and money= ? and num = ? and bool_shop = 1 ";
        int i = BaseDao.executeUpdata(sql, k , r.getBuyers(), r.getBusiness(), r.getDishename(), r.getMoney(), r.getNum());
       if(k==2) {
           String sql1 = "update user set money=money + ? where name = ? and id =1";
           int j = BaseDao.executeUpdata(sql1, r.getMoney(), OpenBusiness.username);
           if (i > 0 && j > 0) return true;
           else return false;
       }
       else {
           String sql2="update user set money=money +? where name =? and id=0";
           int f = BaseDao.executeUpdata(sql2,r.getMoney(), r.getBuyers());
           if(i>0&&f>0)return true;
           else return false;

       }
    }
    //填充收益金额
    public static String  money() throws Exception {
        String sql ="select * from user where id=1 and name = ?";
       ResultSet r= BaseDao.executeQuery(sql, OpenBusiness.username);
       r.next();
       String i=r.getString("money");
       return i;
    }


}

